class AdminController < ApplicationController
  
  layout 'admin'

  before_filter :authorize_access, :except => [:login, :send_login, :index]

  def index
  end
  
  def login
    @user = User.new
  end
  
  def send_login
    @user = User.new(params[:user])
    logged_in_user = @user.try_to_login
    if logged_in_user && logged_in_user.level > 0
      session[:user_id] = logged_in_user.id
      session[:user_level] = logged_in_user.level
      flash[:notice] = "You are now logged in."
      redirect_to(:action => 'index')
    else
      flash[:notice] = "Username/password combination incorrect. Please make sure your caps lock key is off and try again."
      redirect_to(:action => 'index')
    end
  end
  
  def logout
    session[:user_id] = nil
    session[:user_level] = nil
    flash[:notice] = "You are now logged out."
    redirect_to(:action => 'index')
  end
  
end
